home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / VLIB200.ZIP / DEMOPROC.C < prev    next >
C/C++ Source or Header  |  1993-11-04  |  41KB  |  1,499 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM:    Vlibdemo.exe
  4.  
  5.     PURPOSE:    To demonstrate the usage of Visualib(TM) functions.
  6.     
  7.     PROVIDER:   Visual Technology, Co.
  8.                 P.O.Box 901-413
  9.                 Kansas City, MO 64190
  10.                 Tel. (219) 289-0235
  11.                 Fax. (816) 746-6618
  12.     
  13.     DATE:        May, 1993
  14.  
  15. ****************************************************************************/
  16.  
  17. #include <windows.h>
  18. #include <stdlib.h>
  19. #include <math.h>
  20. #include "visualib.h"
  21. #include "menu.h"
  22. #include "vlibdemo.h"
  23. #include "demoproc.h"
  24.  
  25. HINSTANCE    hdllinst = 0;
  26.  
  27. int WINAPI LibMain (HINSTANCE hinst, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine)
  28. {
  29.     if (cbHeapSize != 0)
  30.         UnlockData (0);
  31.     hdllinst = hinst;
  32.     return (1);
  33. }
  34.  
  35. VOID WINAPI MinRoutine (int nParameter, LPSTR lpszParam2)
  36. {
  37.     
  38. }
  39.  
  40. int    WINAPI WEP (int nParameter)
  41. {
  42.     if (nParameter == WEP_SYSTEM_EXIT) {
  43.         return (1);
  44.     }
  45.     else if (nParameter == WEP_FREE_DLL) {
  46.         return (1);
  47.     }
  48.     else {
  49.         return (1);
  50.     }
  51. }
  52.  
  53. VOIDED    LineDemo2D (HDC hdc)
  54. {
  55.     SetViewerName (VL_CURRENT, "2D Lines");
  56.     PenColor (hdc, VL_RED);
  57.     MoveTo2D (hdc, 0, 0);
  58.     LineTo2D (hdc, 1, 1);
  59.     RLineTo2D (hdc, -2, 0);
  60.     RLineTo2D (hdc, 0, -2);
  61.     RLineTo2D (hdc, 2, 0);
  62.     RLineTo2D (hdc, 0, 2);
  63.     RMoveTo2D (hdc, 1, 1);
  64.     LineTo2D (hdc, -2, 2);
  65.     PenColor (hdc, VL_BLUE);
  66.     MoveTo2H (hdc, 1, 1, 0.5f);
  67.     LineTo2H (hdc, 0, 1, 0);
  68.     LineTo2H (hdc, 0, 0, 1);
  69.     MoveTo2H (hdc, -1, 1, 0.5f);
  70.     LineTo2H (hdc, -1, 0, 0);
  71.     LineTo2H (hdc, 0, 0, 1);
  72.     MoveTo2H (hdc, -1, -1, 0.5f);
  73.     LineTo2H (hdc, 0, -1, 0);
  74.     LineTo2H (hdc, 0, 0, 1);
  75.     MoveTo2H (hdc, 1, -1, 0.5f);
  76.     LineTo2H (hdc, 1, 0, 0);
  77.     LineTo2H (hdc, 0, 0, 1);
  78.     PenColor (hdc, VL_GREEN);
  79.     Line2D (hdc, -15, 5, 15, 5);
  80.     Line2D (hdc, -15, -5, 15, -5);
  81.     Line2D (hdc, -5, -15, -5, 15);
  82.     Line2D (hdc, 5, -15, 5, 15);
  83.     Line2D (hdc, -15, 0, 0, 15);
  84.     Line2D (hdc, 15, 0, 0, 15);
  85.     Line2D (hdc, 0, -15, 15, 0);
  86.     Line2D (hdc, 0, -15, -15, 0);
  87.     PenColor (hdc, VL_YELLOW);
  88.     Line2H (hdc, -5, 5, 0.75f, 5, 5, 0.75f);
  89.     Line2H (hdc, -5, -5, 0.75f, 5, -5, 0.75f);
  90.     Line2H (hdc, -5, -5, 0.75f, -5, 5, 0.75f);
  91.     Line2H (hdc, 5, -5, 0.75f, 5, 5, 0.75f);
  92.     PenColor (hdc, VL_BROWN);
  93.     RLine2D (hdc, 2, 3, -5, -5);
  94. }
  95.  
  96. VOIDED    PolylineDemo2D (HDC hdc)
  97. {
  98.     COORD    poly[] = {-1, -1, -1, 1, 1, 1, 1, -1};
  99.  
  100.     SetViewerName (VL_CURRENT, "2D PolyLines");
  101.     PenColor (hdc, VL_RED);
  102.     Polyline2D (hdc, VL_2D, poly, 4);
  103.     PushTransformation2D (NULL);
  104.     TranslateTo2D (3, 3);
  105.     ClosedPolyline2D (hdc, VL_2D, poly, 4);
  106.     TranslateTo2D (10, 0);
  107.     ClosedPolyline2D (hdc, VL_2D, poly, 4);
  108.     TranslateTo2D (10, -6);
  109.     ClosedPolyline2D (hdc, VL_2D, poly, 4);
  110.     TranslateTo2D (-10, -6);
  111.     ClosedPolyline2D (hdc, VL_2D, poly, 4);
  112.     TranslateTo2D (-10, 6);
  113.     ClosedPolyline2D (hdc, VL_2D, poly, 4);
  114.     PopTransformation2D (NULL);
  115.     LineTo2D (hdc, 0, 0);
  116. }
  117.  
  118. VOIDED    PointerDemo2D (HDC hdc)
  119. {
  120.     real    x, y, a;
  121.     short    i;
  122.  
  123.     SetViewerName (VL_CURRENT, "2D Pointers");
  124.     PenColor (hdc, VL_YELLOW);
  125.     for (i = 0, a = 0; i < 12; i++, a += 0.5f) {
  126.         x = (real) cos (a) * 9;
  127.         y = (real) sin (a) * 5;
  128.         Pointer2D (hdc, 0, 0, x, y, 1, 0.5f, VL_CLOSEDARROW);
  129.     }
  130. }
  131.  
  132. VOIDED    MarkDemo2D (HDC hdc)
  133. {
  134.     short    i;
  135.     real    x, y;
  136.  
  137.     SetViewerName (VL_CURRENT, "2D Marks");
  138.     PenColor (hdc, VL_BLUE);
  139.     for (i = 0, x = -9, y = -6; i < 10; i++, x += 2)
  140.         Mark2D (hdc, x, y, i+2, i+2, VL_CIRCLEMARK);
  141.     for (i = 0, x = -9, y = -4; i < 10; i++, x += 2)
  142.         Mark2D (hdc, x, y, i+2, i+2, VL_CROSSMARK);
  143.     for (i = 0, x = -9, y = -2; i < 10; i++, x += 2)
  144.         Mark2D (hdc, x, y, i+2, i+2, VL_XMARK);
  145.     for (i = 0, x = -9, y = 0; i < 10; i++, x += 2)
  146.         Mark2D (hdc, x, y, i+2, i+2, VL_TRIANGLEMARK);
  147.     for (i = 0, x = -9, y = 2; i < 10; i++, x += 2)
  148.         Mark2D (hdc, x, y, i+2, i+2, VL_BOXMARK);
  149.     for (i = 0, x = -9, y = 4; i < 10; i++, x += 2)
  150.         Mark2D (hdc, x, y, i+2, i+2, VL_DIAMONDMARK);
  151.     for (i = 0, x = -9, y = 6; i < 10; i++, x += 2)
  152.         Mark2D (hdc, x, y, i+2, i+2, VL_HEXAGONMARK);
  153. }
  154.  
  155. VOIDED    LabelDemo2D (HDC hdc)
  156. {
  157.     SetViewerName (VL_CURRENT, "2D Labels");
  158.     TextColor (hdc, VL_RED, VL_WHITE, TRANSPARENT);
  159.     PenColor (hdc, VL_GREEN);
  160.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  161.     Label2D (hdc, 0, 0, "Center & BaseLine");
  162.     Mark2D (hdc, 0, 0, 15, 5, VL_CROSSMARK);
  163.     SetTextAlign (hdc, TA_CENTER | TA_TOP);
  164.     Label2D (hdc, 0, 3, "Center & Top");
  165.     Mark2D (hdc, 0, 3, 15, 3, VL_CROSSMARK);
  166.     SetTextAlign (hdc, TA_CENTER | TA_BOTTOM);
  167.     Label2D (hdc, 0, -3, "Center & Bottom");
  168.     Mark2D (hdc, 0, -3, 15, 3, VL_CROSSMARK);
  169.  
  170.     SetTextAlign (hdc, TA_LEFT | TA_BASELINE);
  171.     Label2D (hdc, 3.5f, 0, "Left & BaseLine");
  172.     Mark2D (hdc, 3.5f, 0, 15, 5, VL_CROSSMARK);
  173.     SetTextAlign (hdc, TA_LEFT | TA_TOP);
  174.     Label2D (hdc, 3.5f, 3, "Left & Top");
  175.     Mark2D (hdc, 3.5f, 3, 15, 3, VL_CROSSMARK);
  176.     SetTextAlign (hdc, TA_LEFT | TA_BOTTOM);
  177.     Label2D (hdc, 3.5f, -3, "Left & Bottom");
  178.     Mark2D (hdc, 3.5f, -3, 15, 3, VL_CROSSMARK);
  179.  
  180.     SetTextAlign (hdc, TA_RIGHT | TA_BASELINE);
  181.     Label2D (hdc, -3.5f, 0, "Right & BaseLine");
  182.     Mark2D (hdc, -3.5f, 0, 15, 5, VL_CROSSMARK);
  183.     SetTextAlign (hdc, TA_RIGHT | TA_TOP);
  184.     Label2D (hdc, -3.5f, 3, "Right & Top");
  185.     Mark2D (hdc, -3.5f, 3, 15, 3, VL_CROSSMARK);
  186.     SetTextAlign (hdc, TA_RIGHT | TA_BOTTOM);
  187.     Label2D (hdc, -3.5f, -3, "Right & Bottom");
  188.     Mark2D (hdc, -3.5f, -3, 15, 3, VL_CROSSMARK);
  189. }
  190.  
  191. VOIDED    NetDemo2D (HDC hdc)
  192. {
  193.     COORD    net[140];
  194.     short    i, j, index = 0;
  195.     real    x, y;
  196.  
  197.     PenColor (hdc, VL_BLUE);
  198.     ;
  199.     for (i = 0, y = -6.5f; i < 7; i++, y += 2) {
  200.         for (j = 0, x = -9.5f; j < 10; j++, x += 2) {
  201.             net[index++] = x + ((real) rand () / RAND_MAX);
  202.             net[index++] = y + ((real) rand () / RAND_MAX);
  203.         }
  204.     }
  205.     Net2D (hdc, VL_2D, (LPCOORD) net, 7, 10);
  206.     SetViewerName (VL_CURRENT, "2D Net");
  207. }
  208.  
  209. VOIDED    Prime2D (HDC hdc, int func)
  210. {
  211.     PenColor (hdc, VL_WHITE);
  212.     DisplayViewerFrame (hdc, VL_CURRENT);
  213.     switch (func) {
  214.         case IDM_2DPRIME_LINE:
  215.             LineDemo2D (hdc);
  216.             break;
  217.         case IDM_2DPRIME_POLYLINE:
  218.             PolylineDemo2D (hdc);
  219.             break;
  220.         case IDM_2DPRIME_POINTER:
  221.             PointerDemo2D (hdc);
  222.             break;
  223.         case IDM_2DPRIME_MARK:
  224.             MarkDemo2D (hdc);
  225.             break;
  226.         case IDM_2DPRIME_LABEL:
  227.             LabelDemo2D (hdc);
  228.             break;
  229.         case IDM_2DPRIME_ARROW:
  230.             SetViewerName (VL_CURRENT, "3D Arrows");
  231.             break;
  232.         case IDM_2DPRIME_NET:
  233.             NetDemo2D (hdc);
  234.             break;
  235.     }
  236.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  237.     DisplayViewerName (hdc, VL_CURRENT, FALSE);
  238. }
  239.  
  240. VOIDED    LineDemo3D (HDC hdc)
  241. {
  242.     SetViewerName (VL_CURRENT, "3D Lines");
  243.     PenColor (hdc, VL_RED);
  244.     MoveTo3D (hdc, 0, 0, 0);
  245.     LineTo3D (hdc, 10, 10, 0);
  246.     RLineTo3D (hdc, 0, -20, 0);
  247.     RLineTo3D (hdc, -20, 0, 0);
  248.     RLineTo3D (hdc, 0, 20, 0);
  249.     RLineTo3D (hdc, 20, 0, 0);
  250.     PenColor (hdc, VL_BLUE);
  251.     MoveTo3H (hdc, 1, 1, 0, 0.5f);
  252.     LineTo3H (hdc, 0, 1, 0, 0);
  253.     LineTo3H (hdc, 0, 0, 0, 1);
  254.     MoveTo3H (hdc, -1, 1, 0, 0.5f);
  255.     LineTo3H (hdc, -1, 0, 0, 0);
  256.     LineTo3H (hdc, 0, 0, 0, 1);
  257.     MoveTo3H (hdc, -1, -1, 0, 0.5f);
  258.     LineTo3H (hdc, 0, -1, 0, 0);
  259.     LineTo3H (hdc, 0, 0, 0, 1);
  260.     MoveTo3H (hdc, 1, -1, 0, 0.5f);
  261.     LineTo3H (hdc, 1, 0, 0, 0);
  262.     LineTo3H (hdc, 0, 0, 0, 1);
  263.     PenColor (hdc, VL_YELLOW);
  264.     MoveTo3D (hdc, 100, 100, 90);
  265.     LineTo3D (hdc, 10, 0, 0);
  266.     MoveTo3D (hdc, 100, 100, 90);
  267.     LineTo3D (hdc, 0, 10, 0);
  268.     MoveTo3D (hdc, 100, 100, 90);
  269.     LineTo3D (hdc, 0, 0, 10);
  270. }
  271.  
  272. VOIDED    PolylineDemo3D (HDC hdc)
  273. {
  274.     COORD    poly[] = {-1, -1, -1, 1, 1, 1, 1, -1};
  275.  
  276.     SetViewerName (VL_CURRENT, "3D PolyLines");
  277.     PenColor (hdc, VL_RED);
  278.     Polyline3D (hdc, VL_2D, poly, 4);
  279.     PushTransformation3D (NULL);
  280.     Scale3D (5, 5, 5);
  281.     TranslateTo3D (3, 3, 0);
  282.     PenColor (hdc, VL_GREEN);
  283.     ClosedPolyline3D (hdc, VL_2D, poly, 4);
  284.     TranslateTo3D (10, 0, 0);
  285.     PenColor (hdc, VL_BLUE);
  286.     ClosedPolyline3D (hdc, VL_2D, poly, 4);
  287.     TranslateTo3D (10, -6, 0);
  288.     PenColor (hdc, VL_YELLOW);
  289.     ClosedPolyline3D (hdc, VL_2D, poly, 4);
  290.     TranslateTo3D (-10, -6, 0);
  291.     PenColor (hdc, VL_BROWN);
  292.     ClosedPolyline3D (hdc, VL_2D, poly, 4);
  293.     TranslateTo3D (-10, 6, 0);
  294.     PenColor (hdc, VL_WHITE);
  295.     ClosedPolyline3D (hdc, VL_2D, poly, 4);
  296.     PopTransformation3D (NULL);
  297.     LineTo3D (hdc, 0, 0, 0);
  298. }
  299.  
  300. VOIDED    PointerDemo3D (HDC hdc)
  301. {
  302.